package com.pz.chat.controller;

import com.pz.chat.entity.resultmap.ChatMessageResultMap;
import com.pz.chat.service.ChatMessageService;
import com.pz.chat.vo.ChatTargetOptionResVo;
import com.pz.gulimall.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/chat-msg")
public class ChatMessageController {
    @Autowired
    private ChatMessageService chatMessageService;

    /**
     * 获取所有对于 {userId} 的消息(用作显示聊天对象)
     * @param userId 登录用户的ID
     */
    @GetMapping("/get-messages-list/{userId}")
    public R getAllMsg(@PathVariable String userId) {
        List<ChatTargetOptionResVo> targetMsgOptions = chatMessageService.getAllMsgGroupByToId(userId);
        return R.okData(targetMsgOptions);
    }

    /**
     * 用户{userId}确认收到{targetId}的所有消息
     * @param userId 登录用户ID
     * @param targetId 聊天对象ID
     */
    @GetMapping("/ack-message/{userId}/{targetId}")
    public R responseMsgAck(@PathVariable String userId, @PathVariable String targetId) {
        chatMessageService.ackTargetMsgs(userId, targetId);
        return R.ok();
    }
}
